package br.com.xp.galera.login.dao;


import java.util.List;

import org.hibernate.Query;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import br.com.xp.galera.domain.Usuario;

@Transactional
public class LoginDaoImpl extends HibernateDaoSupport implements LoginDao {

	@SuppressWarnings("unchecked")
	public Usuario entrar(String login, String senha){
		
		Usuario usuario = null;
		Session session = getSession(false);
        
        try {
        	
            Query query = session.createQuery("from Usuario u where u.login=? and u.senha=?");
            
        	query.setString(0, login);
            query.setString(1, senha);

            List<Usuario> result = query.list();
            if (result != null && result.size() > 0) {
            	usuario = result.get(0);
            }
            
        }
        catch (HibernateException ex) {
            throw convertHibernateAccessException(ex);
        }
		
        return usuario;
        
	}

}
